<template>
	<satri-page :padding="20">
		<satri-confirm ref="Confirm"> </satri-confirm>

		<satri-confirm ref="Confirm2">
			<satri-input />
		</satri-confirm>

		<satri-confirm ref="Confirm3"> </satri-confirm>

		<satri-confirm ref="Confirm4"> </satri-confirm>

		<satri-card label="基础用法">
			<satri-button @tap="open">打开</satri-button>
		</satri-card>

		<satri-card label="自定义内容">
			<satri-button @tap="open2">打开</satri-button>
		</satri-card>

		<satri-card label="关闭回掉">
			<satri-button @tap="open3">打开</satri-button>
		</satri-card>

		<satri-card label="不同类型">
			<satri-button @tap="open4('success')">成功</satri-button>
			<satri-button @tap="open4('warning')">警告</satri-button>
			<satri-button @tap="open4('error')">错误</satri-button>
		</satri-card>
	</satri-page>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useUi } from "/$/satri-ui";

const ui = useUi();

const Confirm = ref<SatriConfirm.Ref>();
const Confirm2 = ref<SatriConfirm.Ref>();
const Confirm3 = ref<SatriConfirm.Ref>();
const Confirm4 = ref<SatriConfirm.Ref>();

function open() {
	Confirm.value?.open({
		title: "提示",
		message: "你有一个待取信件",
		callback(action) {
			console.log(action);

			switch (action) {
				case "confirm":
					ui.showToast("领取成功");
					break;

				case "cancel":
					ui.showToast("已取消");
					break;

				case "close":
					ui.showToast("已关闭");
					break;
			}
		},
	});
}

function open2() {
	Confirm2.value?.open({
		title: "提示",
	});
}

function open3() {
	Confirm3.value?.open({
		title: "提示",
		message: "你有一个待取信件",
		beforeClose(action, { done, showLoading, hideLoading }) {
			console.log(action);

			if (action == "confirm") {
				showLoading();

				setTimeout(() => {
					done();
					ui.showToast("领取成功");
				}, 1500);
			} else {
				done();
			}
		},
	});
}

function open4(type: "success" | "warning" | "error") {
	Confirm4.value?.open({
		title: "提示",
		message: "这是一条消息",
		type,
		showCancelButton: false,
	});
}
</script>
